home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
BSCRIERR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-10
|
6KB
|
186 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: bscrierr.c
// Title: Base library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains a critical error handler for DOS. This critical error
// handler does not query the user for a response.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <bs.h>
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
static USHORT usError = 0;
#if OS_DOS && COMPILER_BORLAND
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
static void _interrupt (*oldint24)(void);
//----------------------------------------------------------------------------
// Description: Critical error handler.
// Parameters:
// Returns:
//----------------------------------------------------------------------------
void _CDECL_ _FAR_ CritErrHandler(unsigned deverr, unsigned errval, unsigned _FAR_ *devhdr)
{
NOTUSED(devhdr);
if (deverr & 0x8000) // Non-disk error
_hardretn(5); // Access denied
usError = (errval & 0x00FF) + 1; // Get error code and abort!
_hardresume(_HARDERR_FAIL);
return ;
}
//----------------------------------------------------------------------------
// Description: Install critical error handler.
// Parameters:
// Returns:
//----------------------------------------------------------------------------
VOID FN_E CritErrInitialize(void)
{
if (oldint24 == NULL)
{
oldint24 = _dos_getvect(0x24);
_harderr(CritErrHandler);
BaseExitFunc((PFNEXIT)CritErrTerminate, SYS_EXIT_PRIORITY);
}
return ;
}
//----------------------------------------------------------------------------
// Description: Remove critical error handler.
// Parameters:
// Returns:
//----------------------------------------------------------------------------
VOID FN_E CritErrTerminate(void)
{
if (oldint24 && oldint24 == _dos_getvect(0x24))
_dos_setvect(0x24,oldint24);
oldint24 = NULL;
return ;
}
#endif // #if OS_DOS && COMPILER_BORLAND
//----------------------------------------------------------------------------
// Description: Return critical error handler code.
// Parameters:
// Returns: Error code.
// 1 Write protect
// 2 Unknown unit
// 3 Drive not ready
// 4 Unknown command
// 5 Data error (CRC)
// 6 Bad request
// 7 Seek error
// 8 Unknown media type
// 9 Sector not found
// 10 Printer out of paper
// 11 Write fault
// 12 Read fault
// 13 General failure
// 14 Reserved
// 15 Reserved
// 16 Invalid disk change
//----------------------------------------------------------------------------
USHORT FN_E CritErr(void)
{
return usError;
}
//----------------------------------------------------------------------------
// Description: Reset critical error handler flag
// Parameters:
// Returns:
//----------------------------------------------------------------------------
VOID FN_E CritErrReset(void)
{
usError = 0;
errno = 0; // Also reset errno
return ;
}
//----------------------------------------------------------------------------
// Description: Run standard test suite
// Parameters: sTest Test to run.
// 0 Run all default tests (except).
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_TEST
BOOL FN CritErrTest(SHORT sTest)
{
NOTUSED(sTest);
#if OS_DOS && COMPILER_BORLAND
KbdFlush();
Output("Critical error handler enabled.\nOpen the door of drive A:\n");
while (!KbdReady())
;
KbdChar();
CritErrReset();
Output("fopen() returned %p\n", fopen("A:temp.dat", "w"));
Output("Critical error code is %ld\n", (LONG)CritErr());
#else
Output("This test is only valid under DOS\n");
#endif
return TRUE;
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------